﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using HMS.ClassLibrary;
using HMS.Report;


namespace HMS
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            InitializeAccessControlSettings();
            
        }
        private void InitializeAccessControlSettings()
        {
            switch (HMSApplication.Session.AccessType)
            {
                case AccessType.Administrator:
                    SetupRibbonTab.Visibility = Visibility.Collapsed;
                    AdminRibbonTab.Visibility = Visibility.Visible;
                    break;

                case AccessType.Employee:
                    SetupRibbonTab.Visibility = Visibility.Collapsed;
                    AdminRibbonTab.Visibility = Visibility.Collapsed;
                    break;

                case AccessType.Manager:
                    SetupRibbonTab.Visibility = Visibility.Collapsed;
                    AdminRibbonTab.Visibility = Visibility.Collapsed;
                    ReportRibbonTab.Visibility = Visibility.Visible;
                    break;
                default:
                    break;
            }
            
        }
        private bool IsWindowOpen(Type windowType)
        {
            try
            {
                foreach (Window window in this.OwnedWindows)
                {
                    if (window.GetType() == windowType)
                    {
                        window.Activate();
                        return true;
                    }
                }
                return false;
            }
            catch (Exception)
            {
                
                return false;
            }
        }
        private void ChannelingRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(ChannlingWindow)))
            {
                ChannlingWindow ChannelingWindow = new ChannlingWindow();
                ChannelingWindow.Owner = this;
                ChannelingWindow.Show();
            }
        }

        private void XRayRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(XRayWindow)))
            {
                XRayWindow XRayWindow = new XRayWindow();
                XRayWindow.Owner = this;
                XRayWindow.Show();
            }
        }

        private void LabTestRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(LabTestWindow)))
            {
                LabTestWindow labTestWindow = new LabTestWindow();
                labTestWindow.Owner = this;
                labTestWindow.Show();
            }
        }

        private void ScanRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(ScanWindow)))
            {
                ScanWindow scanWindow = new ScanWindow();
                scanWindow.Owner = this;
                scanWindow.Show();
            }
        }

        private void DoctorRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(DoctorWindow)))
            {
                DoctorWindow doctorWindow = new DoctorWindow();
                doctorWindow.Owner = this;
                doctorWindow.Show();
            }
        }

        private void ReportManagerRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(ReportManager)))
            {
                ReportManager reportManagerWindow = new ReportManager();
                reportManagerWindow.Show();
            }
        }

        private void UserRibbonButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsWindowOpen(typeof(UserWindow)))
            {
                UserWindow userWindow = new UserWindow();
                userWindow.Owner = this;
                userWindow.Show();
            }
        }

       
    }
}
